Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / prefs / src / commonMain / kotlin / org / meshtastic / core / prefs / discovery / MeshBeaconPrefsImpl.kt

Displaying Raw • Download

core/prefs/src/commonMain/kotlin/org/meshtastic/core/prefs/discovery/MeshBeaconPrefsImpl.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.15 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.prefs.discovery

Tff7b72import T7ee787androidx.datastore.preferences.core.edit
Tff7b72import T7ee787androidx.datastore.preferences.core.stringPreferencesKey
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.SupervisorJob
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.SharingStarted
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.collectLatest
Tff7b72import T7ee787kotlinx.coroutines.flow.filterNotNull
Tff7b72import T7ee787kotlinx.coroutines.flow.map
Tff7b72import T7ee787kotlinx.coroutines.flow.stateIn
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.prefs.di.UiDataStore
Tff7b72import T7ee787org.meshtastic.core.repository.MeshBeaconPrefs

Tf0883e@Single
Tff7b72class T56d364MeshBeaconPrefsImplTb4b4b4(Tff7b72private Tff7b72val Te6edf3dataStoreTb4b4b4: Te6edf3UiDataStoreTb4b4b4, Te6edf3dispatchersTb4b4b4: Te6edf3CoroutineDispatchersTb4b4b4) Tb4b4b4: Te6edf3MeshBeaconPrefs Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3scope Tff7b72= Te6edf3CoroutineScopeTb4b4b4(Te6edf3SupervisorJobTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3dispatchersTb4b4b4.Te6edf3defaultTb4b4b4)

Tff7b72override Tff7b72val Te6edf3storedBeaconsTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ListTff7b72<Tffa657StringTff7b72>Tff7b72> Tff7b72=
Te6edf3dataStoreTb4b4b4.Te6edf3data
Tb4b4b4.Te6edf3map Tb4b4b4{ Te6edf3prefs Tff7b72-Tff7b72>
Tff7b72val Te6edf3raw Tff7b72= Te6edf3prefsTff7b72[Te6edf3KEY_STORED_BEACONSTff7b72] Tff7b72?: Ta5d6ff"Ta5d6ff"
Tff7b72if Tb4b4b4(Te6edf3rawTb4b4b4.Te6edf3isBlankTb4b4b4(Tb4b4b4)Tb4b4b4) Te6edf3emptyListTb4b4b4(Tb4b4b4) Tff7b72else Te6edf3rawTb4b4b4.Te6edf3splitTb4b4b4(Te6edf3RECORD_DELIMITERTb4b4b4)
Tb4b4b4}
Tb4b4b4.Te6edf3stateInTb4b4b4(Te6edf3scopeTb4b4b4, Te6edf3SharingStartedTb4b4b4.Te6edf3EagerlyTb4b4b4, Te6edf3emptyListTb4b4b4(Tb4b4b4)Tb4b4b4)

T8b949e// Single conflated writer: rapid add()/dismiss() calls each publish the full latest list here, and one collector
T8b949e// serializes the DataStore writes (latest-wins). Avoids launch-per-call races that could persist a stale snapshot.
T8b949e// runCatching keeps a best-effort write failure (e.g. disk I/O) from escaping as an uncaught coroutine exception —
T8b949e// the next add/dismiss retries, and on restart we hydrate from the last successful write.
Tff7b72private Tff7b72val Te6edf3pendingWrite Tff7b72= Te6edf3MutableStateFlowTff7b72<Te6edf3ListTff7b72<Tffa657StringTff7b72>Tff7b72?Tff7b72>Tb4b4b4(Tff7b72nullTb4b4b4)

Tff7b72init Tb4b4b4{
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Te6edf3pendingWriteTb4b4b4.Te6edf3filterNotNullTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3collectLatest Tb4b4b4{ Te6edf3records Tff7b72-Tff7b72>
Te6edf3runCatching Tb4b4b4{ Te6edf3dataStoreTb4b4b4.Te6edf3edit Tb4b4b4{ Tffa657itTff7b72[Te6edf3KEY_STORED_BEACONSTff7b72] Tff7b72= Te6edf3recordsTb4b4b4.Te6edf3joinToStringTb4b4b4(Te6edf3RECORD_DELIMITERTb4b4b4) Tb4b4b4} Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tff7b72override Tff7b72fun Td2a8ffsetStoredBeaconsTb4b4b4(Te6edf3recordsTb4b4b4: Te6edf3ListTff7b72<Tffa657StringTff7b72>Tb4b4b4) Tb4b4b4{
Te6edf3pendingWriteTb4b4b4.Te6edf3value Tff7b72= Te6edf3records
Tb4b4b4}

Tff7b72private Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72val Te6edf3KEY_STORED_BEACONS Tff7b72= Te6edf3stringPreferencesKeyTb4b4b4(Ta5d6ff"Ta5d6ffmesh_beacon_stored_offersTa5d6ff"Tb4b4b4)

T8b949e// Newline can never appear in a beacon record (fields are numeric + base64), so it is a safe row separator.
Tff7b72const Tff7b72val Te6edf3RECORD_DELIMITER Tff7b72= Ta5d6ff"Ta5d6ff\Ta5d6ffnTa5d6ff"
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s